<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // var a = 1
    // var b = a
    // console.log(b);


    var obj1 = {
      name:'obj1',
      age:28,
      aihao:11,
      brother:{
        name:'只因',
      }
    }
    // // var obj2 = obj1 
    // // console.log(obj2.name);
    // function clone1(target) {
    //   var res = {}
    //   for(var k in target){
    //     res[k] = target[k]
    //   }
    //      return res
    // }
    // var obj3 = clone1(obj1)
    // console.log(obj3);
    // //obj1.brother.name = '鸡！'
    // console.log(obj3);


    function clone2(target) {
      var res = {}
      for(var k in target){
        if (typeof target[k] == 'object'){
          res[k] = clone2(target[k])
        }
        else{
           res[k] = target[k]
        }
       
      }
         return res
    }
      var obj4 = clone2(obj1);
      obj1.brother.name = '鸡！'
      console.log(obj4);


      // var a =5
      // var b ='5'
      // if (a==b){
      //   console.log('你太笨了');
      // }

  </script>
</body>
</html>